#include "Game.h"



CAction::CAction()
{
	m_bShow = FALSE ;
}

CAction::~CAction()
{
	
}


INT CAction::Enter(DWORD dwtab[], INT ix, INT iy, DWORD Time, DWORD Round) 
{
	if(!m_bShow)
	{
		m_bShow = TRUE;
		m_SprTab = dwtab;
		m_Round = (INT)Round -1;
		m_TipEjectTime = GetTabIDNum(m_SprTab)*C_GAME_FRAME_TIME;
		m_TipTime 	=m_TipEjectTime + Time;
		m_TimeType =  eClockSystem;
		m_TipTimeStart = GetTime((GmClockType)m_TimeType) ;
		m_SprCnt = -1;
		m_Spr.SetPriority(C_Pri_GameStart);
		m_Spr.SetLayerID(eLayUI);
		m_Spr.SetPaletteID(ePalUI);
		m_Spr.SetCoordinate(ix, iy);
		SetManager(g_GameApp.GetEntityManager());
		CEntity::Enter();
		return TRUE;
	}
	return FALSE;
}

INT CAction::Execute()
{
	if(GetTime((GmClockType)m_TimeType) < m_TipTimeStart + m_TipTime)
	{
		if(m_SprCnt <  (INT)GetTabIDNum(m_SprTab) -1 )
		{
			m_Spr.SetSprID(GetTabIDByIndex(m_SprTab, ++m_SprCnt));
			m_Spr.Update();
		}
		else if(m_Round > 0)
		{
			m_Round--;
			m_SprCnt = -1;
		}
		return TRUE;
	}
	else
	{
		Del();
		return FALSE;
	}
}

INT CAction::Out() 
{
	Del();
	CEntity::Out();
	return TRUE;
}

void CAction::Del() 
{
	if(m_bShow)
	{
		m_bShow = FALSE;
		m_Spr.Del();
	}
}

BOOL CAction::IsEnd()
{
	if(GetTime((GmClockType)m_TimeType) > m_TipTimeStart + m_TipTime + 300)
	{
		return TRUE;
	}

	return FALSE ;
}

